#!/usr/bin/python3
# ******************************************************************************
# Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
# licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#     http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# ******************************************************************************/
import time

import asyncio
from aiohttp import ClientSession

from python_learn.elasticsearch.operation import Es

if __name__ == '__main__':
    es_client = Es()
    start_time = time.time()
    try:
        loop = asyncio.get_event_loop()
        response = loop.run_until_complete(es_client.async_es.index(index='test', body={"name": {"lhw"}}))
    except Exception as e:
        print('insert failed')
        print(f"take time is {time.time() - start_time}")
    # 删除所有index，可指定某个index
    # 查询index结构
    # es_client.query_mapping(index="sig_info")

    # 插入data.json中的数据,该步骤包含了删除，不用单独删除
    # loop = asyncio.get_event_loop()
    # es_client.delete_index()
    # xml_data = es_client.parse_date()
    # loop.run_until_complete(es_client.insert_data(xml_data))

    # 获取所有的index
    # loop = asyncio.get_event_loop()
    # loop.run_until_complete(es_client.get_indices())

    # 查询数据，body自行拼接
    # loop = asyncio.get_event_loop()
    # query_body = {"query": {"match_all": {}}, "size": 6}
    # loop.run_until_complete(es_client.query_data_old(index="branch_info", body=query_body))

    # 下面不用管，调试使用
    # query_body = {"gitee_branch.keyword": "openEuler-20.03-LTS-SP1"}
    # loop.run_until_complete(es_client.query_data("obs_info", body=query_body))
    # query_body = {"query": {"wildcard": {"gitee_branch.keyword": "openEuler*"}}, "_source": ["repo_name"],
    #               "size": 100}
